from flask import render_template, url_for, flash, redirect, get_flashed_messages
from app import app

from app.forms import LoginForm

@app.route('/')
@app.route('/index')
def index():
    user = {'username':'张老三'}
    posts = [
        {
            'author': {'username': '毛泽东'},
            'body': '这是模版模块中循环例子1-毛泽东思想'
        },
        {
            'author': {'username': '习近平'},
            'body': '这是模版模块中循环例子2-二十大召开'
        }
    ]
    
    return render_template('index.html',  title='我的', user=user, posts=posts)

@app.route('/login', methods=['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash(f'用户的登录名是：{form.username.data}, 是否记住我：{form.remember_me.data}')
        return redirect(url_for('index'))
    return render_template('login.html', title='登录', form=form)